<template>
	<view class="discount">
		<view class="dt">
			
		</view>
		<view class="coupon">
			<view class="co-item">
				<text class="iconfont">&#xe76b;</text>
				<text>本店购买含优惠券</text>
				<input type="number" v-model="full" maxlength="5" />
				<text>元，</text>
				<text>立减</text>
				<input type="number" v-model="reduce" maxlength="5" />
				<text>元</text>
				<button @click="onAdd" class="button">增加</button>
			</view>
			<block v-if="fullList.length">
				<view class="already">
					已添加的满减
				</view>
				<view class="co-item" v-for="(data,index) in fullList" :key="index">
					<text class="iconfont">&#xe76b;</text>
					<text>本店购买含优惠券</text>
					<text style="color: #FF557D;">{{data.amout_srtart}}</text>
					<text>元，</text>
					<text>立减</text>
					<text style="color: #FF557D;">{{data.discount}}</text>
					<text>元</text>
					<button @click="onDel(data.benefitid)" class="button">删除</button>
				</view>
				
			</block>
			
		</view>
		
		</view>
</template>

<script>
	export default {
		data() {
			return {
				fullList: [], // 满减列表
				full: '', // 满金额
				reduce: '', // 减金额
				
			};
		},
		onLoad() {
			this.getFull();
		},
		onPullDownRefresh() {
			this.getFull();
		},
		methods: {
			async onAdd() { // 增加满减
				if(Number(this.full) <= Number(this.reduce)) {
					uni.showToast({
						title: '优惠金额大于等于实际金额~~',
						icon: 'none'
					})
					return
				}
				let a = await this.$http.setShopBenefit({amout_srtart: this.full,discount: this.reduce});
				
				uni.showToast({
					title: a.message,
					icon: 'none'
				});
				this.full = '';
				this.reduce = '';
				this.getFull();
			},
			async getFull() { // 满减查询
				let a = await this.$http.getFull();
				if(a.code == 200) {
					this.fullList = a.data;
					uni.stopPullDownRefresh()
					return
				}
				uni.showToast({
					title: a.message,
					icon: 'none'
				});
			},
			async onDel(id) { // 删除满减
				let a = await this.$http.delShopBenefit({benefitid: id});
				uni.showToast({
					title: a.message,
					icon: 'none'
				});
				this.getFull();
			},
			
			
		},
	}
</script>

<style lang="scss" scoped>
	@import 'static/css/refund.scss';
</style>
